package com.hqyj.fj.javaSpringBoot.modules.spider.service.impl;

import com.hqyj.fj.javaSpringBoot.modules.spider.dao.CoronavirusDao;
import com.hqyj.fj.javaSpringBoot.modules.spider.entity.Coronavirus;
import com.hqyj.fj.javaSpringBoot.modules.spider.service.CoronavirusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class CoronavirusServiceImpl implements CoronavirusService {
    @Autowired
    private CoronavirusDao coronavirusDao;

    @Override
    public List<Coronavirus> getCoronaviruses() {
        List<Coronavirus> coronavirusList= Optional
                .ofNullable(coronavirusDao.getCornavirus())
                .orElse(Collections.emptyList());
        return coronavirusList.stream()
                .sorted(Comparator.comparing(Coronavirus::getDate))
                .collect(Collectors.toList());
    }
}
